<template>
	<view>
		<view class="container">
			<view class="recharge-order">
				<scroll-view @scrolltolower="bindDownLoad" scroll-y :style="[{height:  Height}] ">
					<view v-for="(item,index) in list.data " :key="index" class="order-item dis-flex flex-x-between flex-y-center">
						<view class="item-left">
							<view class="rec-status">
								<text>充值成功</text>
							</view>
							<view class="rec-time">
								<text>{{ item.pay_time.text }}</text>
							</view>
						</view>
						<view class="item-right">
							<text>+{{ item.actual_money }}元</text>
						</view>
					</view>
					<!-- 没有记录 -->
					<view class="yoshop-notcont" v-if="list.data && !list.data.length && !isLoading ">
						<text class="iconfont icon-wushuju"></text>
						<text class="cont">亲，暂无充值记录哦</text>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		computed: {
			Height() {
				return uni.upx2px(this.scrollHeight * 2) + 'px';
			}
		},
		data() {
			return {
				list: {}, // 充值记录
				isLoading: true, // 是否正在加载中
				page: 1, // 当前页码
				scrollHeight: null,
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			let _this = this;
			// 设置列表容器高度
			_this.setListHeight();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
			let _this = this;
			// 获取充值记录
			_this.getRechargeOrder();
		},

		methods: {
			/**
			 * 获取充值记录列表
			 */
			getRechargeOrder(isPage, page) {
				let _this = this;
				_this._get('recharge.order/lists', {
					page: page || 1
				}, function(result) {
					// console.log(result.data);
					let resList = result.data.list,
						dataList = _this.list;
					if (isPage == true) {
						_this.setData({
							'list.data': dataList.data.concat(resList.data),
							isLoading: false,
						});
					} else {
						_this.setData({
							list: resList,
							isLoading: false,
						});
					}
				});
			},

			/**
			 * 设置列表容器高度
			 */
			setListHeight: function() {
				let _this = this,
					systemInfo = uni.getSystemInfoSync();
				_this.setData({
					scrollHeight: systemInfo.windowHeight * 0.98
				});
			},

			/**
			 * 下拉到底加载数据
			 */
			bindDownLoad() {
				let _this = this;
				// 已经是最后一页
				if (_this.page >= _this.list.last_page) {
					_this.setData({
						no_more: true
					});
					return false;
				}
				// 加载下一页列表
				_this.getRechargeOrder(true, ++_this.page);
			},
		}
	}
</script>

<style>
	page,
	.container {
		background: #fff;
	}

	.recharge-order {
		padding: 0 30upx;
	}

	.order-item {
		font-size: 32upx;
		padding: 10upx 20upx;
		line-height: 1.8;
		border-bottom: 1upx solid rgb(238, 238, 238);
	}

	.order-item .rec-time {
		color: rgb(160, 160, 160);
		font-size: 26upx;
	}
</style>
